********************************************************************************************************************************
***   Replication file for:                                                                                                  ***
***   Braun, S. T. and Stuhler, J. (2024). The Economic Consequences of Being Widowed by War: A Life-Cycle Perspective.	     ***
***	  Journal of Public Economics                                                                                            ***
***   							                                                                                             ***
***   ---   Main Do-File   ---   																							 ***
***	  --- 	Mikrozensus Zusatzerhebung 1971                                                                                  ***
***
***   Software:
***   Analyses run on Windows using Stata version 16 
***
***   Notes: 
***	  Data are stored in /data
***   Tables are outputted to /results/tables
***   Figures are outputted to /results/figures
***   To perform, a clean run delete the following folders: /results, /processed
***
***
********************************************************************************************************************************


*** Users must define global macro to point to the folder that contains the main do file
global widowsallbus ""

* Confirm that the global for the project root directory was defined
assert !missing("$widowsallbus")

* Initialize log
clear
set more off
cap mkdir "$widowsallbus/scripts/logs"
cap log close
local datetime : di %tcCCYY.NN.DD!-HH.MM.SS `=clock("$S_DATE $S_TIME", "DMYhms")'
local logfile "$widowsallbus/scripts/logs/`datetime'.log.txt"
log using "`logfile'", text

* Configure Stata's library environment and record system parameters
run "$widowsallbus/scripts/programs/_config.do"

* Stata version control
version 16.1

* Create directories for output files
cap mkdir "$widowsallbus/results"
cap mkdir "$widowsallbus/results/tables"

* Run project analysis
*do "$widowsallbus/scripts/_install_stata_packages.do"
do "$widowsallbus/scripts/1-allbus-prep-1980-86.do"
do "$widowsallbus/scripts/2-allbus-prep-1988.do"
do "$widowsallbus/scripts/3-allbus-prep-merge.do"
do "$widowsallbus/scripts/4-allbus-regression.do"

* End log
di "End date and time: $S_DATE $S_TIME"
log close

exit